package com.activenetwork.util.verification;

import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.WebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.activenetwork.custom.uielement.decorate.IdentifierFactory;
import com.activenetwork.util.EnvContext;
import com.activenetwork.util.verification.gson.FailurePoint;

public class checkText implements VerificationAction {	
	private static Logger logger = LoggerFactory.getLogger(checkText.class);
	private String pageName;
	private String pageField;
	private String text;
	private String caseName;
	private WebElement element;
	
	
	public checkText(String pageName, String pageField, String text, String caseName){
		this.pageName = pageName;
		this.pageField = pageField;
		this.text = text;
		this.caseName = caseName;
		this.element = IdentifierFactory.createWebElement(pageName, pageField);
	}
	
	public checkText(WebElement element, String text, String caseName){
		this.element = element;
		this.text = text;
		this.caseName = caseName;
	}

	@Override
	public void verify() {	
		if(!StringUtils.equalsIgnoreCase(element.getText().trim(), text)){
			logger.error(pageName + "-" + pageField + 
					" expect:" + "\"" + text + "\"" + " actual:" + "\"" + element.getText().trim()+"\"");
			EnvContext.failurePointTL.get().add(
					new FailurePoint(caseName, "Verify Input text node", pageName + "-" + pageField + 
							" expect:" + "\"" + text + "\"" + " actual:" + "\"" + element.getText().trim()+"\""));
		}
	}

}
